﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>箱码档案信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
    <script type="text/html" id="barDemo">

    </script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">

                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="barCode" placeholder="箱码编码" autocomplete="off" class="layui-input" id="barCode">

                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="capacity" placeholder="容量" autocomplete="off" class="layui-input" id="capacity">
                            </div>

                            <div class="layui-inline layui-show-xs-block">
                                <select id="wareHouse" name="wareHouse" class="wareHouse">
                                    <option value="">所属仓库</option>
                                </select>
                            </div>

                            <div class="layui-inline layui-show-xs-block">
                                <select id="barStatus" name="barStatus" class="barStatus">
                                    <option value="">箱码状态</option>
                                </select>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-filter="sreach" id="userSearch" type="button" onclick="loadData()"><i class="layui-icon">&#xe615;</i></button>
                            </div>

                        </form>
                    </div>

                    <div class="layui-card-body" id="layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>
    var barCodes = "";
    var currPage = 1;//首先默认值为1，防止出错
    function loadData() {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var dUrl = "../Bar/GetDataList?dataType=box&condition=" + conditon;
            var table = layui.table;
            table.render({
                elem: '#list'
                , cols: [[ //标题栏
                    { type: 'checkbox' }
                    , { field: 'id', title: 'ID', width: 80 }
                    , { field: 'barCode', title: '箱码', width: 130 }
                    , { field: 'capacity', title: '箱容量', width: 110, }
                    , { field: 'statusName', title: '箱码状态', width: 90 }
                    , { field: 'isFullName', title: '是否满箱', width: 90 }
                    , { field: 'wareHouseName', title: '所属仓库', width: 110 }
                    , { field: 'positionName', title: '所属货位', width: 100 }
                    , { field: 'createtime', title: '创建时间', width: 140 }
                    , { field: 'right', title: '数据操作', toolbar: '#barDemo', width: 85, fixed: 'right' }
                ]], done: function (res, curr, count) {
                    $("[data-field='id']").css('display', 'none');//隐藏列
                    currPage = curr;
                    $.each(res['data'], function (i, j) {
                        if (j['isFull'] == "1") {
                            TableRowColor('layui-table-main', i, '#92f0bb');
                        }
                    });
                }
                //   , height: $(document).height() - $('#list').offset().top - 20
                , url: dUrl
                , skin: 'row' //表格风格
                , even: true
                , page: { layout: ['count', 'prev', 'page', 'next', 'skip', 'limit'], groups: 1, first: false, last: false }
                //, page: true //是否显示分页
                , limits: [20, 35, 50]
                , limit: 20 //每页默认显示的数量
                , id: "tData"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == 'print') {
                    SSO("reBar", data.barCode);
                } else if (obj.event == 'del') {
                    layer.confirm('确认要作废选中条码？', function (index) {
                        var info = DelData(data.barCode);
                        if (info.Result) {
                            obj.del();
                        } else {
                            layer.msg(info.Message);
                        }
                        layer.close(index);
                    });
                } else if (obj.event == 'tmzy') {
                    if (data.zy != "1") {
                        layer.msg('此数据无占用信息'); return;
                    }
                    var url = "../Bar/BarZhanYong?barCode=" + data.barCode;
                    NewOpenPage(url, data.barCode + "-条码占用", "90%", "90%", "tData", currPage, dUrl);

                }

            });
            //监听工具条
            table.on('checkbox(list)', function (obj) {
                var data = obj.data;

                //为父窗口input赋值
                barCodes = "";
                var checkStatus = table.checkStatus('list');
                var infos = "";
                for (var i = 0; i < checkStatus.data.length; i++) {
                    infos = infos + checkStatus.data[i].barCode + ",";
                }
                barCodes = infos.substr(0, infos.length - 1);
            });
        });
    }

    $(function () {
        //获取列表
        wareInfo();
        DictionaryDropDown("bst", "barStatus", "");
        loadData();
    })
    function openWin() {
        InfoOpenPage("../Bar/AddBarCode?planCode=0", "条码添加", "95%", "90%");
    }

    function wareInfo() {
        $.ajax({
            url: "../Basis/GetWareHouse",
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
                if (data.Result) {
                    var datas = data.Data;
                    for (var i = 0; i < datas.length; i++) {
                        $(".wareHouse").append("<option value=\"" + datas[i]["houseCode"] + "\" >" + datas[i]["houseName"] + "</option>");
                    }

                }
            }
        });
    }
    /**
   条码作废
   **/
    function DelData(boxCode) {
        var info = undefined;
        $.ajax({
            url: "../Bar/DropBoxCode",
            data: { barCode: barCode },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {

                info = data;
            }
        });
        return info;
    }
   
</script>